package com.maxmlr.music.song.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.maxmlr.music.common.bean.ResultBean;
import com.maxmlr.music.common.bean.ResultPageBean;
import com.maxmlr.music.common.param.PageParam;
import com.maxmlr.music.song.param.SongInfoParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import lombok.extern.slf4j.Slf4j;
import com.maxmlr.music.common.base.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import com.maxmlr.music.song.service.SongService;
import com.maxmlr.music.song.entity.Song;
import io.swagger.annotations.*;

import java.io.Serializable;
import java.util.Arrays;

/**
 * @author max
 * @version 1.0
 * @ClassName SongController
 * @Description 歌曲信息表 控制器
 * @Copyright Copyright (c) 2020: www.maxmlr.com.
 * @since 2020-06-07
 */
@Slf4j
@RestController
@Api(value = "/song/song", tags = "Song 控制器")
@RequestMapping("/song/song")
public class SongController extends BaseController<SongService, Song> {

    @Autowired
    public SongService service;

    @GetMapping("/list")
    public ResultPageBean<SongInfoParam> listSong(PageParam pageParam, SongInfoParam inParam) {
        Page page = getPage(pageParam);
        service.listSong(page, inParam);
        return ResultPageBean.ok(page);
    }

    @GetMapping("/list-param")
    public ResultPageBean<SongInfoParam> listSongParam(PageParam pageParam, SongInfoParam inParam, @RequestParam Integer type) {
        Page<Song> page = getPage(pageParam);
        Page<SongInfoParam> paramPage = service.listSongParam(page, inParam, type);
        return ResultPageBean.ok(paramPage);
    }

    /**
     * @Description 通过id获取Param
     * @author max
     * @since 2019-05-11
     */
    @GetMapping("/get-param")
    @ApiOperation(value = "/get-param", notes = "通过id获取Param")
    public ResultBean<SongInfoParam> getSongInfoParam(@ApiParam("id") @RequestParam Integer id,
                                           @ApiParam("type") @RequestParam Integer type) {
        return ResultBean.ok(service.getSongInfoParam(id, type));
    }

    /**
     * 保存
     *
     * @param song
     * @return ResultBean<Boolean>
     */
    @PostMapping
    @RequiresPermissions("song:song:add" )
    public ResultBean<Boolean> save(SongInfoParam param) {
        return ResultBean.ok(service.saveParam(param));
    }

    /**
     * 修改
     *
     * @param song
     * @return ResultBean<Boolean>
     */
    @PutMapping
    @RequiresPermissions("song:song:edit" )
    public ResultBean<Boolean> update(SongInfoParam param) {
        return ResultBean.ok(service.updateParamById(param));
    }

    /**
     * 删除
     *
     * @param id
     * @return ResultBean<Boolean>
     */
    @DeleteMapping("/remove/{id}" )
    @RequiresPermissions("song:song:remove" )
    public ResultBean<Boolean> remove(@PathVariable("id" ) Serializable id) {
        return ResultBean.ok(service.removeById(id));
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return ResultBean<Boolean>
     */
    @DeleteMapping("/batch-remove")
    @RequiresPermissions("song:song:batch-remove")
    public ResultBean<Boolean> batchRemove(@RequestParam("ids[]") Serializable[] ids){
        return ResultBean.ok(service.removeByIds(Arrays.asList(ids)));
    }
}
